package cn.adkii.springframework.utils;

/**
 * @author malingdi
 * @description
 * @date 2023/11/23 10:44
 */
public class ClassUtils {

    public static ClassLoader getDefaultClassLoader(){
        ClassLoader cl = null;
        try {
            cl = Thread.currentThread().getContextClassLoader();
        }catch (Throwable ex){
            // cannot access thread context ClassLoader - falling back to system clas loader ...
        }
        if (cl == null){
            cl = ClassUtils.class.getClassLoader();
        }
        return cl;
    }

    /**
     * check whether the specified class is a CGLIB-generated class.
     */
    public static boolean isCglibProxyClass(Class<?> clazz){
        return (clazz != null && isCglibProxyClassName(clazz.getName()));
    }

    /**
     *  Check whether the specified class name is a CGLIB-generated class.
     */
    public static boolean isCglibProxyClassName(String className){
        return (className != null && className.contains("$$"));
    }
}
